using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Components.Portal;
using NCS.Library;
using NCS.Module.CMS.Library.Zones;
using NCS.Library.Utilities;

namespace NCS.Module.CMS.Web.Movies
{
    public partial class HeaderSearch : CMSWebControl
    {
        public string lblMenu = "";
        public string lblPortal = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["keysearch"] != null && Request.QueryString["keysearch"] != "")
                    txtSearch.Text = Request.QueryString["keysearch"].Replace("%20", "&nbsp;");
            }
            int catid = ConvertUtility.ToInt32(Request.QueryString["catid"]);
            if (catid != 0)
            {
                Advertisement1.Param = "catid";
            }
            DataTable dtPortal = PortalController.GetPortalsByLang(AppEnv.GetLanguage());
            for (int i = 0; i < dtPortal.Rows.Count; i++)
            {
                if (ConvertUtility.ToInt32(dtPortal.Rows[i]["PortalID"]) == ConvertUtility.ToInt32(AppEnv.PortalId()))
                {
                    lblPortal += "<li class=\"first selected\">";
                    lblPortal += " <a href='" + BuildUrlbyPortal(ConvertUtility.ToInt32(dtPortal.Rows[i]["PortalID"])) + "'>" + ConvertUtility.ToString(dtPortal.Rows[i]["Portal_Name"]) + "</a>";
                    lblPortal += "</li>";
                }
                else
                {
                    lblPortal += "<li>";
                    lblPortal += " <a href='" + BuildUrlbyPortal(ConvertUtility.ToInt32(dtPortal.Rows[i]["PortalID"])) + "'>" + ConvertUtility.ToString(dtPortal.Rows[i]["Portal_Name"]) + "</a>";
                    lblPortal += "</li>";
                }
            }
            
            //DataTable dt = ZoneController.GetZonesVisbleInTop();
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    if (i == 0)
            //    {
            //        lblMenu += "<li class=\"first\">";
            //        lblMenu += " <a href='" + BuildUrlByZone(ConvertUtility.ToInt32(dt.Rows[i]["Zone_ID"]), ConvertUtility.ToInt32(dt.Rows[i]["Portal_TabControlID"])) + "'>" + ConvertUtility.ToString(dt.Rows[i]["Zone_Name"]) + "</a>";
            //        lblMenu += "</li>";
            //    }
            //    else if (i == 2)
            //    {
            //        lblMenu += "<li class=\"last\">";
            //        lblMenu += " <a href='" + BuildUrlByZone(ConvertUtility.ToInt32(dt.Rows[i]["Zone_ID"]), ConvertUtility.ToInt32(dt.Rows[i]["Portal_TabControlID"])) + "'>" + ConvertUtility.ToString(dt.Rows[i]["Zone_Name"]) + "</a>";
            //        lblMenu += "</li>";
            //    }
            //    else
            //    {
            //        lblMenu += "<li>";
            //        lblMenu += " <a href='" + BuildUrlByZone(ConvertUtility.ToInt32(dt.Rows[i]["Zone_ID"]), ConvertUtility.ToInt32(dt.Rows[i]["Portal_TabControlID"])) + "'>" + ConvertUtility.ToString(dt.Rows[i]["Zone_Name"]) + "</a>";
            //        lblMenu += "</li>";

            //    }
            //}
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect(BuildUrlSearch(txtSearch.Text.TrimEnd()));
        }
    }
}